<!DOCTYPE html>
<html lang="en">
<head>
    <meta name="layout" content="bocMain"/>
    <title>进件作业系统</title>
</head>

<body>
    <header class="header-title">基础信息选择</header>
    <g:form action="createOpportunityInfoSave" method="post" class="myForm">

        <div class="weui-cells weui-cells_form">
            <div class="weui-cell weui-cell_select weui-cell_select-after">
                <div class="weui-cell__hd"><label class="weui-label">渠道</label></div>
                <div class="weui-cell__bd">
                    <g:select class="weui-select" name="channel" id="channel" from="${channelList}" optionKey="id" optionValue="name" noSelection="['': '渠道选择']"/>
                </div>
            </div>

            <div class="weui-cell weui-cell_select weui-cell_select-after">
                <div class="weui-cell__hd"><label class="weui-label">产品</label></div>
                <div class="weui-cell__bd">
                    <g:select class="weui-select" name="product" id="product" from="${productList}" optionKey="id" optionValue="name" noSelection="['': '产品选择']"/>
                </div>
            </div>

            <div class="weui-cell weui-cell_select weui-cell_select-after">
                <div class="weui-cell__hd"><label class="weui-label">商户</label></div>
                <div class="weui-cell__bd">
                    <g:select class="weui-select" name="account" id="account" from="${accountList}" optionKey="id" optionValue="name" noSelection="${['': '商户选择']}"/>
                </div>
            </div>
        </div>
    </g:form>

    <div class="bigBtn">
        <button type="button" class="weui-btn weui-btn_primary" id="submit">下一步</button>
    </div>

<script>
    $(function () {
        $("#submit").click(function ()
        {

            var channel = $("#channel").val().trim();
            if (!channel) {
                helpMessage("请选择渠道");
                return;
            }
            var product = $("#product").val().trim();
            if (!product) {
                helpMessage("请选择产品");
                return;
            }
            var account = $("#account").val().trim();
            if (!account) {
                helpMessage("请选择商户");
                return;
            }

            $(".myForm").submit();
        })

        function helpMessage(message) {
            $(".helpMsg").text(message).fadeIn(200);
            setTimeout(function () {
                $(".helpMsg").fadeOut(200);
            }, 2000);
        }

        $("#channel").bind("change", function(){
            $("#account option").remove();
            $("#s2id_account span:first").html("商户选择");
            var channel = $("#channel").val()
            $("#account").append("<option value='' >商户选择</option>")
            if(channel=='-1' || channel==''){
                return
            }
            $.ajax({
                url: "/bocAppOpportunity/getAccountByChannelId",
                type: "POST",
                data: {'channel': channel} ,
                success: function(result){
                    console.log(result)
                    for(var i=0; i < result.accountList.length; i++){
                        $("#account").append("<option value=" + result.accountList[i][0] + ">" + result.accountList[i][1] + "</option>")
                    }
                }
            });
        });

        // $("#account").bind("change", function(){
        //     $("#product option").remove();
        //     $("#s2id_product span:first").html("产品选择");
        //     var account = $("#account").val()
        //     $("#product").append("<option value='' >产品选择</option>")
        //     if(account=='-1' || account==''){
        //         return
        //     }
        //     $.ajax({
        //         url: "/bocAppOpportunity/getProductByAccountId",
        //         type: "POST",
        //         data: {'account': account} ,
        //         success: function(result){
        //             console.log(result)
        //             for(var i=0; i < result.productList.length; i++){
        //                 $("#product").append("<option value=" + result.productList[i][0] + ">" + result.productList[i][1] + "</option>")
        //             }
        //         }
        //     });
        // });

        $("#product").bind("change", function(){
            $("#account option").remove();
            $("#s2id_account span:first").html("商户选择");
            var product = $("#product").val()
            $("#account").append("<option value='' >商户选择</option>")
            if(product=='-1' || product==''){
                return
            }
            $.ajax({
                url: "/bocAppOpportunity/getAccountByProductId",
                type: "POST",
                data: {'product': product} ,
                success: function(result){
                    console.log(result)
                    for(var i=0; i < result.productList.length; i++){
                        $("#account").append("<option value=" + result.productList[i][0] + ">" + result.productList[i][1] + "</option>")
                    }
                }
            });
        });

    })

</script>

</body>
</html>
